<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Friend_link extends CIC_A_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	
	function index()
	{
		$data	= $this->get_friend_link();
		$this->load->view('admin/friend_link/index',$data);
	}
	
	function get_friend_link()
	{
		$where	= '';
		$and 	= '';
		$url = site_url('admin/friend_link/index?');
		$data['page']	 = $this->page($url, $this->cic_model->get_total_rows('friend_link'), $this->per_page,TRUE);
		$data['friend_link'] = $this->cic_model->get_all('friend_link',$where,array('link_create_time','desc'),$this->per_page,$this->input->get('per_page'));
		return $data;
	}
	
	function content_add()
	{
		$this->load->view('admin/friend_link/content_add');
	}
	
	function content_edit()
	{
		$data = array(
				'friend_link'			=> $this->cic_model->get_one('friend_link',array('link_id'=>$this->uri->segment(4))),
		);
		$this->load->view('admin/friend_link/content_edit',$data);
	}
	function add_content()
	{
		//$this->validate('friend_link', 'admin/friend_link/content_add');
		$data = array(
				'link_name'			=> $this->input->post('link_name'),
				'link_url'			=> $this->input->post('link_url'),
				'link_desc'			=> $this->input->post('link_desc'),
				'link_logo'			=> $this->input->post('link_logo'),
				'link_sort'			=> $this->input->post('link_sort'),
				'link_create_time'	=> time(),
		);
		if($this->cic_model->insert('friend_link',$data))
		{
			$this->message->msg('添加成功！',site_url('admin/friend_link/index'));
		}else{
			$this->message->msg('添加失败！',site_url('admin/friend_link/content_add'));
		}
	}
	
	function edit_content()
	{
		//$this->validate('friend_link', 'admin/friend_link/content_edit/'.$this->uri->segment(4));
		$data = array(
				'link_name'			=> $this->input->post('link_name'),
				'link_url'			=> $this->input->post('link_url'),
				'link_desc'			=> $this->input->post('link_desc'),
				'link_logo'			=> $this->input->post('link_logo'),
				'link_sort'			=> $this->input->post('link_sort'),
		);
		if($this->cic_model->update('friend_link',$data,array('link_id'=>$this->uri->segment(4))))
		{
			$this->message->msg('修改成功！',site_url('admin/friend_link/index'));
		}else{
			$this->message->msg('未做任何修改！',site_url('admin/friend_link/content_edit/'.$this->uri->segment(4)));
		}
	}
	
	function delete_content()
	{
		if($this->cic_model->delete('friend_link',array('link_id'=>$this->input->post('link_id'))))
		{
			echo 1;
		}else{
			echo 0;
		}
	}
}